﻿import QtQuick 2.12
import QtCharts 2.3
import QtQuick.Controls 2.12

//这个是按照百分比，显示每个人在每一个catregory中占有得比例

ChartView {
    id: chartView
    title: "大于50分的考核分分布"
    titleColor: "white"

    anchors.fill: parent
    antialiasing: true
  //  theme: ChartView.ChartThemeDark
    legend.alignment: Qt.AlignBottom
    legend.labelColor:"white"
    legend.markerShape:Legend.MarkerShapeRectangle

    PercentBarSeries {
        id: pBSeries
        axisX: BarCategoryAxis {
            categories: ["5", "4", "3", "2", "1"]
            labelsColor: "#13B2E8"
            gridLineColor: "#13B2E8"
            color: "#13B2E8"
        }
        axisY: ValueAxis {
            labelsColor: "#13B2E8"
            gridLineColor: "#13B2E8"
            color: "#13B2E8"
        }
        labelsPosition: AbstractBarSeries.LabelsInsideEnd
        labelsVisible: true

        onHovered: function(status, index, barset) {
            toolTipPop.visible = status;
            if (status) {
             //   let pos = chartView.mapToPosition(point, chartView.series("KeZhou"));
             //   toolTipPop.x = pos.x + 10;
            //    toolTipPop.y = pos.y - toolTipPop.height / 2;

                toolTipPop.x = index;
                toolTipPop.y = barset.at(index);
                toolTipPop.text = "横坐标:%1\n".arg(barset.label) + "纵坐标:%1".arg(barset.values[index]);
            }
        }
    }


    ToolTip {
        id: toolTipPop
        parent: chartView
        z:3
        background: Rectangle {
            color: "#393232"
            radius: 5
        }
        contentItem: Text {
            text: toolTipPop.text
            color: "white"
            font.pixelSize: 15
            padding: 5
            lineHeight: 1.4
        }
    }

    Component.onCompleted: {
        let plants = query.getPlants();
        plants = JSON.parse(plants);
        plants.forEach(getUnqualifiedScore);
    }

    function getUnqualifiedScore(plantName) {
        let score = query.getScore(plantName);
        let obj = JSON.parse(score);
        let sumScore = 0.0;
        let scores = new Array;
        for (var prop in obj) {
            sumScore += obj[prop].score;
            scores.push(obj[prop].score);
        }
        if (sumScore > 50)
            pBSeries.append(modelH.trPlantName(plantName), scores);
    }
}

